<?php
namespace Admin\Controller;
use Think\Controller;
//工具
class ToolController extends CommonController {

    public function index()
    {

    }

    public function check_friend()
    {
        return false;
        header("Content-Type: text/html;charset=utf-8");
        $where              =   array();
        $where['module']    =   'GuessNewSong';
        $field              =   array('id','log');
        $log_data   =   M('yao_log')->where($where)->field($field)->select();

        echo '有数据：'.count($log_data);
        echo '</br>';

        if (! empty($log_data))
        {
            foreach ($log_data as $val)
            {

                $input_data             =   json_decode($val['log'],true);

                if (! empty($input_data['uid']) && ! empty($input_data['share_uid']))
                {

                    $where_friend                           =   array();
                    $field_friend                           =   array('id');
                    $where_friend['my_member_id']           =   $input_data['share_uid'];
                    $where_friend['coupling_member_id']     =   $input_data['uid'];

                    $friend_data    =   M('newsong_relationship')->where($where_friend)->field($field_friend)->find();

                    if (! empty($friend_data))
                    {

                        $where_delete       =   array();
                        $where_delete['id'] =   $val['id'];
                        $result = M('yao_log')->where($where_delete)->delete();
                        if (! empty($result))
                        {
                            echo '存在好友关系id:'.$friend_data['id'].'删除成功：id:'.$val['id'].'</br>';
                        }

                    }
                    else
                    {
                        $insert_data                            =   array();
                        $insert_data['my_member_id']            =   $input_data['share_uid'];
                        $insert_data['coupling_member_id']      =   $input_data['uid'];
                        $insert_data['createtime']              =   time();
                        $insert_data['appid']                   =   'wx370386b7eb0c04bc';

                        $result     =   M('newsong_relationship')->add($insert_data);

                        if (! empty($result))
                        {
                            $where_delete       =   array();
                            $where_delete['id'] =   $val['id'];
                            $result = M('yao_log')->where($where_delete)->delete();
                            if (! empty($result))
                            {
                                echo '删除成功：id:'.$val['id'].'</br>';
                            }
                        }

                    }


                }


            }

        }

    }

    public function synchronous_data()
    {
        return false;
        $newsong_cash   =       M('newsong_cash')->select();
        if (! empty($newsong_cash))
        {
            foreach ($newsong_cash as $val)
            {
                $where_memebr           =   array();
                $field                  =   array('uid','nickname','avatarurl');
                $where_memebr['uid']    =   $val['uid'];
                $member_data    =   M('newsong_member')->where($where_memebr)->field($field)->find();
                if (! empty($member_data))
                {

                    $where_cash                 =   array();
                    $where_cash['id']           =   $val['id'];
                    $update_data                =   array();
                    $update_data['nickname']    =   $member_data['nickname'];
                    $update_data['avatarurl']   =   $member_data['avatarurl'];

                    $resilt = M('newsong_cash')->where($where_cash)->save($update_data);

                    if ($resilt)
                    {
                        echo '更新成功</br>';
                    }
                }

            }

            echo '更新成功66699</br>';
        }
    }

    public function redis_tool()
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1',6379);

        $test   =   $_REQUEST['test'];
        if (empty($test))
        {
            $redis->set('test_redis', 111);
        }
        //获取一个字符串的值
        echo '测试test_redis：'.$redis->get('test_redis'); // 111
    }

    public function redis_clear()
    {
        $Redis  =   S(array('type'=>'redis','host'=>'127.0.0.1','port'=>'6379'));
        $Redis->clear();
        echo '清空redis';
    }

}